﻿'Musjid Display System (MDS or mdsys - for short) is a program written in VB.NET 2008 Express Edition using dotnet Frameword 3.5. Its purpose is to display a dynamic page of information on a large screen (eg. Plasma Screen, TV, etc) situated in a Musjid, with salaah times, hadeeth, messages, etc
'    Copyright (C) 2008 Muhammed Cotwal (muhammedc_AT_gmail.com)

'    This program is free software: you can redistribute it and/or modify
'    it under the terms of the GNU General Public License as published by
'    the Free Software Foundation, either version 3 of the License, or
'    (at your option) any later version.

'    This program is distributed in the hope that it will be useful,
'    but WITHOUT ANY WARRANTY; without even the implied warranty of
'    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'    GNU General Public License for more details.

'    You should have received a copy of the GNU General Public License
'    along with this program.  If not, see <http://www.gnu.org/licenses/>.
' Imports here...
Imports Microsoft.Win32
Imports System.Management
Imports System.Management.Instrumentation
'Module of commonly used functions used throughtout the program
Module modCommon
    'Function to get Hijri Date based on current date
    Public Function GetHigriDate()
        On Error GoTo ertrp
        'Declare Variables (H=Hijri)
        Dim HFullDate, HShortMonth, HFullMonth, HShortDate, HShortYear, HFinalDate, HAdjust
        'Assign Variable - Get info from SQL Query
        HFullDate = frmScreenDisplay.Mds_settingsTableAdapter1.QuerySettings_GetCurrentHijriDate.ToString
        'Since the above includes the time, we need to strip it down to the different date componants viz dd/mm/yyyy
        'First we get the actual Date
        HShortDate = Mid(HFullDate, 1, 2)
        'Next we get the year
        HShortYear = Mid(HFullDate, 7, 4)
        'Then we get the Month and assign the Transliteration of the Month
        HShortMonth = Mid(HFullDate, 4, 2)
        HFullMonth = ""
        If HShortMonth = "01" Then
            HFullMonth = "Muharram"
        End If
        If HShortMonth = "02" Then
            HFullMonth = "Safar"
        End If
        If HShortMonth = "03" Then
            HFullMonth = "Rabi al Awwal"
        End If
        If HShortMonth = "04" Then
            HFullMonth = "Rabi al Akhîr"
        End If
        If HShortMonth = "05" Then
            HFullMonth = "Jumâdal Awwal"
        End If
        If HShortMonth = "06" Then
            HFullMonth = "Jumâdal Akhîr"
        End If
        If HShortMonth = "07" Then
            HFullMonth = "Rajab"
        End If
        If HShortMonth = "08" Then
            HFullMonth = "Sha'bân"
        End If
        If HShortMonth = "09" Then
            HFullMonth = "Ramadân"
        End If
        If HShortMonth = "10" Then
            HFullMonth = "Shawwal"
        End If
        If HShortMonth = "11" Then
            HFullMonth = "Dhu'l-Qa'dah"
        End If
        If HShortMonth = "12" Then
            HFullMonth = "Dhu'l-Hijja"
        End If
        'Since Hijri date is a lunar calandar, we need check if there are any date adjustments and add it to the date
        HAdjust = frmScreenDisplay.Mds_settingsTableAdapter1.QuerySettings_GetHijriAdjustment.ToString
        If HAdjust = "-2" Then
            HShortDate = HShortDate - 2
        End If
        If HAdjust = "-1" Then
            HShortDate = HShortDate - 1
        End If
        If HAdjust = "0" Then
            HShortDate = HShortDate
        End If
        If HAdjust = "+1" Then
            HShortDate = HShortDate + 1
        End If
        If HAdjust = "+2" Then
            HShortDate = HShortDate + 2
        End If
        'Now we construct the date as we wish it to be displayed
        HFinalDate = HShortDate & " " & HFullMonth & " " & HShortYear
        Return HFinalDate
        Exit Function
ertrp:
        ErrorTrap()
    End Function
    'Function to error trap
    Public Function ErrorTrap()
        'Declare Variables
        Dim CurrentStack As New System.Diagnostics.StackTrace(True)
        Dim Myself As String = CurrentStack.GetFrame(0).GetMethod.Name
        Dim MyCaller As String = CurrentStack.GetFrame(1).GetMethod.Name
        Dim cur_file As String = CurrentStack.GetFrame(1).GetFileName
        Dim line_num As Integer = CurrentStack.GetFrame(1).GetFileLineNumber
        'Display an message box with enough information to help us debug the problem quickly
        MsgBox("Error Number: " & Err.Number & vbCrLf & "Error Description: " & Err.Description & vbCrLf & "Called by: " & MyCaller & " at Errortrap location @ line number: " & line_num & vbCrLf & cur_file, MsgBoxStyle.Critical)
        On Error Resume Next
    End Function
    'Sub to update salaah times on display
    Public Sub UpdateSalaahTimes()
        On Error GoTo ertrp
        'Declare Variables (t=time)
        Dim tfajr, tzohr, tasr, tmaghrib, tesha, tsehri, tsunrise, tzawaal, tsunset, tjumma, tjumazan
        'Assign Variables
        'We use the Mid command to only bring out the time in hh:mm format, as it is stored in DB as hh:mm:ss
        tfajr = Mid(frmScreenDisplay.Mds_perpetual_salaah_timesTableAdapter1.QueryToday_Fajr.ToString, 1, 5)
        tzohr = Mid(frmScreenDisplay.Mds_perpetual_salaah_timesTableAdapter1.QueryToday_Zuhr.ToString, 1, 5)
        tasr = Mid(frmScreenDisplay.Mds_perpetual_salaah_timesTableAdapter1.QueryToday_Asr.ToString, 1, 5)
        tmaghrib = Mid(frmScreenDisplay.Mds_perpetual_salaah_timesTableAdapter1.QueryToday_Maghrib.ToString, 1, 5)
        tesha = Mid(frmScreenDisplay.Mds_perpetual_salaah_timesTableAdapter1.QueryToday_Esha.ToString, 1, 5)
        tsehri = Mid(frmScreenDisplay.Mds_perpetual_salaah_timesTableAdapter1.QueryToday_SehriEnds.ToString, 1, 5)
        tsunrise = Mid(frmScreenDisplay.Mds_perpetual_salaah_timesTableAdapter1.QueryToday_Sunrise.ToString, 1, 5)
        tsunset = Mid(frmScreenDisplay.Mds_perpetual_salaah_timesTableAdapter1.QueryToday_Sunset.ToString, 1, 5)
        tzawaal = Mid(frmScreenDisplay.Mds_perpetual_salaah_timesTableAdapter1.QueryToday_Zawaal.ToString, 1, 5)
        tjumma = Mid(frmScreenDisplay.Mds_settingsTableAdapter1.QuerySettings_JummaTime.ToString, 1, 5)
        tjumazan = Mid(frmScreenDisplay.Mds_settingsTableAdapter1.QuerySettings_JummaAzaanTime.ToString, 1, 5)
        'Assign the variables to the time labels
        frmScreenDisplay.lblFajrTime.Text = tfajr
        frmScreenDisplay.lblZohrTime.Text = tzohr
        frmScreenDisplay.lblAsrTime.Text = tasr
        frmScreenDisplay.lblMaghribTime.Text = tmaghrib
        frmScreenDisplay.lblEshaTime.Text = tesha
        frmScreenDisplay.lblSehriTime.Text = tsehri
        frmScreenDisplay.lblSunriseTime.Text = tsunrise
        frmScreenDisplay.lblZawaalTime.Text = tzawaal
        frmScreenDisplay.lblSunsetTime.Text = tsunset
        frmScreenDisplay.lblJummaTime.Text = tjumma
        frmScreenDisplay.lblJummaAzaanTime.Text = tjumazan
        Exit Sub
ertrp:
        ErrorTrap()
    End Sub
    'Sub to update settings that pull information from the DB in order to effect the change.
    Public Sub UpdateSettings()
        On Error GoTo ertrp
        'Declare Variables (n = name)
        Dim nmusjidname
        'Assign Variables
        nmusjidname = frmScreenDisplay.Mds_settingsTableAdapter1.QuerySettings_MusjidName.ToString
        'Assign the variables to the MusjidName labels
        frmScreenDisplay.lblMusjidName.Text = nmusjidname
        'Get HijriDate and add to lblHijriDate
        UpdateDates()
        'Get the string to display in the ticker display
        GetMarqeeText()
        'Get Hadith to start hadith display
        GetHadith()
        'Update Time Highlighting
        HighlightCurrentSalaahTime()
        'Check Skin Status
        SkinMDS()
        'Update Salaah Times
        UpdateSalaahTimes()
        Exit Sub
ertrp:
        ErrorTrap()
    End Sub
    'Sub to update the Gregorian date and Hijri Date
    Public Sub UpdateDates()
        On Error GoTo ertrp
        'Display the updated dates on the date labels
        frmScreenDisplay.lblHijriDate.Text = GetHigriDate()
        frmScreenDisplay.lblGregorianDate.Text = Format(Now, "Long Date")
        Exit Sub
ertrp:
        ErrorTrap()
    End Sub
    'Sub to get a random hadith from the DB
    Public Sub GetHadith()
        On Error GoTo ertrp
        'Using a sql query, we pull a random hadith and display it in the hadith section
        frmScreenDisplay.lblHadith.Text = frmScreenDisplay.Mds_hadithTableAdapter1.QueryHadith_GetRandom.ToString
        Exit Sub
ertrp:
        ErrorTrap()
    End Sub
    'Sub to get the string to display text in the Ticker from the DB
    Public Sub GetMarqeeText()
        On Error GoTo ertrp
        'Display the tickers text from the DB
        frmScreenDisplay.mrqTicker.Text = frmScreenDisplay.Mds_settingsTableAdapter1.QuerySettings_GetMarqeeText.ToString
        Exit Sub
ertrp:
        ErrorTrap()
    End Sub
    'Sub to check that the users regional settings are set in the correct way for MDS to function correctly
    Public Sub TimeAndDateSettings()
        On Error GoTo ertrp
        'Declare Variables
        Dim CurrentDateFormat, CurrentTimeFormat, cTimeStatus, cDateStatus
        'Assign Variables
        CurrentDateFormat = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Control Panel\International", "sLongDate", "")
        CurrentTimeFormat = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Control Panel\International", "sTimeFormat", "")
        'Check to see the current system long date and time settings
        If CurrentDateFormat = "dd MMMM yyyy" Then
            cDateStatus = "1"
        Else
            cDateStatus = "0"
        End If
        If CurrentTimeFormat = "HH:mm:ss tt" Then
            cTimeStatus = "1"
        Else
            cTimeStatus = "0"
        End If
        'If it is set correctly then exit sub
        If cTimeStatus And cDateStatus = "1" Then
            Exit Sub
        Else 'otherwise take action to fix
            'Declase Variable
            Dim mbResult
            'Warn user and give a choice as to whether we should fix or not
            mbResult = MsgBox("WARNING!!! Regional Settings Incorrect!" & vbCrLf & "Your current Time format is '" & CurrentTimeFormat & "' and your current Long Date format is '" & CurrentDateFormat & "'!" & vbCrLf & "This application requres that your Time format be set to 'HH:mm:ss tt'" & vbCrLf & "And that your Long Date Format be sset to 'dd MMMM yyyy'." & vbCrLf & "Would you like MDS to automatically change these Regional Settings for you?", MsgBoxStyle.YesNo)
            If mbResult = MsgBoxResult.Yes Then
                'If user allows fix, change registry keys to affect the change needed
                My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Control Panel\International", "sLongDate", "dd MMMM yyyy")
                My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Control Panel\International", "sTimeFormat", "HH:mm:ss tt")
                'Exit the program and ask user to restart the application
                MsgBox("Registry Modifications Complete... This application will now terminate. Please re execute this application!", MsgBoxStyle.Information)
                End
            Else
                'User request not to fix - So terminate app
                MsgBox("This application will now terminate!", MsgBoxStyle.Critical)
                End
            End If
        End If
        Exit Sub
ertrp:
        ErrorTrap()
    End Sub
    'Sub to check if skin file is in update folder and to apply
    Public Sub SkinMDS()
        On Error GoTo ertrp
        'Declare Variables
        Dim SkinFileExist, SkinDir, SkinOnOff
        'Assign Variables
        SkinOnOff = frmScreenDisplay.Mds_settingsTableAdapter1.QuerySettings_SkinEnabled.ToString
        SkinDir = "C:\MDS-UPDATES"
        SkinFileExist = System.IO.File.Exists(SkinDir & "\skin.bmp")
        'Check whats the setting for skinEnable
        If SkinOnOff = "false" Then
            'Make sure all borders are set because SkinEnable is false
            frmScreenDisplay.Panel1.BorderStyle = BorderStyle.FixedSingle
            frmScreenDisplay.Panel2.BorderStyle = BorderStyle.FixedSingle
            frmScreenDisplay.Panel3.BorderStyle = BorderStyle.FixedSingle
            frmScreenDisplay.Panel4.BorderStyle = BorderStyle.FixedSingle
            frmScreenDisplay.Panel5.BorderStyle = BorderStyle.FixedSingle
            frmScreenDisplay.Panel6.BorderStyle = BorderStyle.FixedSingle
            frmScreenDisplay.lblGregorianDate.BorderStyle = BorderStyle.FixedSingle
            frmScreenDisplay.lblHijriDate.BorderStyle = BorderStyle.FixedSingle
            frmScreenDisplay.lblTime.BorderStyle = BorderStyle.FixedSingle
            frmScreenDisplay.lblSalaahTime.BorderStyle = BorderStyle.FixedSingle
            frmScreenDisplay.lblForbiddenTimes.BorderStyle = BorderStyle.FixedSingle
            frmScreenDisplay.lblOtherTimes.BorderStyle = BorderStyle.FixedSingle
            Exit Sub
        Else
            'Remove all borders to allow for skin to be applied
            frmScreenDisplay.Panel1.BorderStyle = BorderStyle.None
            frmScreenDisplay.Panel2.BorderStyle = BorderStyle.None
            frmScreenDisplay.Panel3.BorderStyle = BorderStyle.None
            frmScreenDisplay.Panel4.BorderStyle = BorderStyle.None
            frmScreenDisplay.Panel5.BorderStyle = BorderStyle.None
            frmScreenDisplay.Panel6.BorderStyle = BorderStyle.None
            frmScreenDisplay.lblGregorianDate.BorderStyle = BorderStyle.None
            frmScreenDisplay.lblHijriDate.BorderStyle = BorderStyle.None
            frmScreenDisplay.lblTime.BorderStyle = BorderStyle.None
            frmScreenDisplay.lblSalaahTime.BorderStyle = BorderStyle.None
            frmScreenDisplay.lblForbiddenTimes.BorderStyle = BorderStyle.None
            frmScreenDisplay.lblOtherTimes.BorderStyle = BorderStyle.None
            'Check if the skin file exist and apply it if it does
            If SkinFileExist = True Then
                frmScreenDisplay.BackgroundImage = Image.FromFile(SkinDir & "\skin.bmp")
            Else
                'Otherwise exit sub
                Exit Sub
            End If
        End If
        Exit Sub
ertrp:
        ErrorTrap()
    End Sub
    'Sub to create and share folder for the update and maintainance of MDS via ClickOnce technology
    Public Sub CreateUpdateFolder()
        On Error GoTo ertrp
        'Declare Variables
        Dim updFolder, updFolderChk
        updFolderChk = System.IO.Directory.Exists("c:\MDS-UPDATES")
        'Check if folder exist
        If updFolderChk = False Then
            'Folder does not exits, so we create it
            updFolder = System.IO.Directory.CreateDirectory("C:\MDS-UPDATES")
            'Declare Variable so that we can get the system to share the folder
            Dim managementClass As New ManagementClass("Win32_Share")
            Dim inParams As ManagementBaseObject = managementClass.GetMethodParameters("Create")
            inParams("Description") = "MDS Updates Folder"
            inParams("Name") = "MDS-UPDATES"
            inParams("Path") = "C:\MDS-UPDATES"
            inParams("Type") = &H0
            Dim outParams As ManagementBaseObject = managementClass.InvokeMethod("Create", inParams, Nothing)
            If Convert.ToUInt32(outParams.Properties("ReturnValue").Value) <> 0 Then
                'Warn us if the system was not able to share
                MsgBox("Unable to complete the update folder creation correctly... Failed at share creation!", MsgBoxStyle.Critical)
            End If
        Else
            'Folder exists - Do nothing
        End If
        Exit Sub
ertrp:
        ErrorTrap()
    End Sub
    'Sub to Highlight the correct times
    Public Sub HighlightCurrentSalaahTime()
        On Error GoTo ertrp
        'Declare Variables (hl=highlight)
        Dim hlFajrBegin, hlSunriseBegin, hlZawaalBegin, hlZuhrBegin, hlAsrBegin, hlSunsetBegin, hlMaghribBegin, hlEshaBegin As Date
        Dim hlFajrEnd, hlSunriseEnd, hlZawaalEnd, hlZuhrEnd, hlAsrEnd, hlSunsetEnd, hlMaghribEnd, hlEshaEnd As Date
        Dim mazCheck, nTime, nTimeHour, nTimeMin, sbTime, sbTimeHour, sbTimeMin, seTime, seTimeHour, seTimeMin, TimeAmOrPm
        'assign variables by changing string db time values into real times and adding or subtracting time as needed
        hlFajrBegin = TimeValue(frmScreenDisplay.Mds_perpetual_salaah_timesTableAdapter1.QueryToday_EarliestFajr.ToString)
        hlFajrEnd = TimeValue(frmScreenDisplay.Mds_perpetual_salaah_timesTableAdapter1.QueryToday_Sunrise.ToString).AddMinutes(-5)  'get Sunrise time - 5
        hlSunriseBegin = TimeValue(frmScreenDisplay.Mds_perpetual_salaah_timesTableAdapter1.QueryToday_Sunrise.ToString).AddMinutes(-2) 'get sunrise time - 2
        hlSunriseEnd = TimeValue(frmScreenDisplay.Mds_perpetual_salaah_timesTableAdapter1.QueryToday_Sunrise.ToString).AddMinutes(2) 'get sunrise time + 2
        hlZawaalBegin = TimeValue(frmScreenDisplay.Mds_perpetual_salaah_timesTableAdapter1.QueryToday_Zawaal.ToString).AddMinutes(-2) 'get zawaal time - 2
        hlZawaalEnd = TimeValue(frmScreenDisplay.Mds_perpetual_salaah_timesTableAdapter1.QueryToday_Zawaal.ToString).AddMinutes(2) 'get zawaal time + 2
        hlZuhrBegin = TimeValue(frmScreenDisplay.Mds_perpetual_salaah_timesTableAdapter1.QueryToday_EarliestZuhr.ToString) 'ger e_zuhr time
        'check shafi/hanafi and issue time accordingly
        mazCheck = frmScreenDisplay.Mds_settingsTableAdapter1.QuerySettings_GetMazhab.ToString
        If mazCheck = "hanafi" Then
            hlZuhrEnd = TimeValue(frmScreenDisplay.Mds_perpetual_salaah_timesTableAdapter1.QueryToday_EarliestAsrHanafi.ToString).AddMinutes(-5)  'get e_asr_hanafi time - 5
            hlAsrBegin = TimeValue(frmScreenDisplay.Mds_perpetual_salaah_timesTableAdapter1.QueryToday_EarliestAsrHanafi.ToString)  'get e_asr_hanafi time
        End If
        If mazCheck = "shafi" Then
            hlZuhrEnd = TimeValue(frmScreenDisplay.Mds_perpetual_salaah_timesTableAdapter1.QueryToday_EarliestAsrShafi.ToString).AddMinutes(-5)  'get e_asr_hanafi time - 5
            hlAsrBegin = TimeValue(frmScreenDisplay.Mds_perpetual_salaah_timesTableAdapter1.QueryToday_EarliestAsrShafi.ToString)  'get e_asr_hanafi time
        End If
        hlAsrEnd = TimeValue(frmScreenDisplay.Mds_perpetual_salaah_timesTableAdapter1.QueryToday_Sunset.ToString).AddMinutes(-5) 'get sunset time - 5
        hlSunsetBegin = TimeValue(frmScreenDisplay.Mds_perpetual_salaah_timesTableAdapter1.QueryToday_Sunset.ToString).AddMinutes(-2) 'get sunset time - 2
        hlSunsetEnd = TimeValue(frmScreenDisplay.Mds_perpetual_salaah_timesTableAdapter1.QueryToday_Sunset.ToString).AddMinutes(2) 'get sunset time + 2
        hlMaghribBegin = TimeValue(frmScreenDisplay.Mds_perpetual_salaah_timesTableAdapter1.QueryToday_Maghrib.ToString) 'get maghrib time
        hlMaghribEnd = TimeValue(frmScreenDisplay.Mds_perpetual_salaah_timesTableAdapter1.QueryToday_EarliestEsha.ToString).AddMinutes(-5) 'get e_esha time - 5
        hlEshaBegin = TimeValue(frmScreenDisplay.Mds_perpetual_salaah_timesTableAdapter1.QueryToday_EarliestEsha.ToString) 'get e_esha time
        hlEshaEnd = TimeValue(frmScreenDisplay.Mds_perpetual_salaah_timesTableAdapter1.QueryToday_SehriEnds.ToString).AddMinutes(-5)  'get sehritime - 5
        TimeAmOrPm = (Right(Now.ToString, 2)).ToString
        'Check current time against variables and highlight times accordingly
init:
        frmScreenDisplay.lblFajr.BackColor = Color.Transparent
        frmScreenDisplay.lblFajrTime.BackColor = Color.Transparent
        frmScreenDisplay.lblSunrise.BackColor = Color.Transparent
        frmScreenDisplay.lblSunriseTime.BackColor = Color.Transparent
        frmScreenDisplay.lblZawaal.BackColor = Color.Transparent
        frmScreenDisplay.lblZawaalTime.BackColor = Color.Transparent
        frmScreenDisplay.lblZohr.BackColor = Color.Transparent
        frmScreenDisplay.lblZohrTime.BackColor = Color.Transparent
        frmScreenDisplay.lblAsr.BackColor = Color.Transparent
        frmScreenDisplay.lblAsrTime.BackColor = Color.Transparent
        frmScreenDisplay.lblSunset.BackColor = Color.Transparent
        frmScreenDisplay.lblSunsetTime.BackColor = Color.Transparent
        frmScreenDisplay.lblMaghrib.BackColor = Color.Transparent
        frmScreenDisplay.lblMaghribTime.BackColor = Color.Transparent
        frmScreenDisplay.lblEsha.BackColor = Color.Transparent
        frmScreenDisplay.lblEshaTime.BackColor = Color.Transparent
fajr:
        If TimeAmOrPm = "AM" Then
            'Get Current Time and Format Correctly
            If Now.Hour < 10 Then
                nTimeHour = "0" & Now.Hour
            Else
                nTimeHour = Now.Hour
            End If
            If Now.Minute < 10 Then
                nTimeMin = "0" & Now.Minute
            Else
                nTimeMin = Now.Minute
            End If
            nTime = nTimeHour & nTimeMin

            'Get Salaah Begin Time
            If hlFajrBegin.Hour < 10 Then
                sbTimeHour = "0" & hlFajrBegin.Hour
            Else
                sbTimeHour = hlFajrBegin.Hour
            End If
            If hlFajrBegin.Minute < 10 Then
                sbTimeMin = "0" & hlFajrBegin.Minute
            Else
                sbTimeMin = hlFajrBegin.Minute
            End If
            sbTime = sbTimeHour & sbTimeMin

            'Get Salaah End Time
            If hlFajrEnd.Hour < 10 Then
                seTimeHour = "0" & hlFajrEnd.Hour
            Else
                seTimeHour = hlFajrEnd.Hour
            End If
            If hlFajrEnd.Minute < 10 Then
                seTimeMin = "0" & hlFajrEnd.Minute
            Else
                seTimeMin = hlFajrEnd.Minute
            End If
            seTime = seTimeHour & seTimeMin

            'Check to see if its salaah/event time and highlight accordingly 
            If nTime >= sbTime AndAlso nTime <= seTime Then
                frmScreenDisplay.lblFajr.BackColor = Color.LightGreen
                frmScreenDisplay.lblFajrTime.BackColor = Color.LightGreen
            Else
                frmScreenDisplay.lblFajr.BackColor = Color.Transparent
                frmScreenDisplay.lblFajrTime.BackColor = Color.Transparent
            End If
        End If
sunrise:
        If TimeAmOrPm = "AM" Then
            'Get Current Time and Format Correctly
            If Now.Hour < 10 Then
                nTimeHour = "0" & Now.Hour
            Else
                nTimeHour = Now.Hour
            End If
            If Now.Minute < 10 Then
                nTimeMin = "0" & Now.Minute
            Else
                nTimeMin = Now.Minute
            End If
            nTime = nTimeHour & nTimeMin

            'Get Salaah Begin Time
            If hlSunriseBegin.Hour < 10 Then
                sbTimeHour = "0" & hlSunriseBegin.Hour
            Else
                sbTimeHour = hlSunriseBegin.Hour
            End If
            If hlSunriseBegin.Minute < 10 Then
                sbTimeMin = "0" & hlSunriseBegin.Minute
            Else
                sbTimeMin = hlSunriseBegin.Minute
            End If
            sbTime = sbTimeHour & sbTimeMin

            'Get Salaah End Time
            If hlSunriseEnd.Hour < 10 Then
                seTimeHour = "0" & hlSunriseEnd.Hour
            Else
                seTimeHour = hlSunriseEnd.Hour
            End If
            If hlSunriseEnd.Minute < 10 Then
                seTimeMin = "0" & hlSunriseEnd.Minute
            Else
                seTimeMin = hlSunriseEnd.Minute
            End If
            seTime = seTimeHour & seTimeMin

            'Check to see if its salaah/event time and highlight accordingly            If nTime >= sbTime AndAlso nTime <= seTime Then
            If nTime >= sbTime AndAlso nTime <= seTime Then
                frmScreenDisplay.lblSunrise.BackColor = Color.LightSalmon
                frmScreenDisplay.lblSunriseTime.BackColor = Color.LightSalmon
                fTimesWarningLabel("sunrise")
            Else
                frmScreenDisplay.lblSunrise.BackColor = Color.Transparent
                frmScreenDisplay.lblSunriseTime.BackColor = Color.Transparent
                fTimesWarningLabel("off")
            End If
        End If
zawaal:
        'Get Current Time and Format Correctly
        If Now.Hour < 10 Then
            nTimeHour = "0" & Now.Hour
        Else
            nTimeHour = Now.Hour
        End If
        If Now.Minute < 10 Then
            nTimeMin = "0" & Now.Minute
        Else
            nTimeMin = Now.Minute
        End If
        nTime = nTimeHour & nTimeMin

        'Get Salaah Begin Time
        If hlZawaalBegin.Hour < 10 Then
            sbTimeHour = "0" & hlZawaalBegin.Hour
        Else
            sbTimeHour = hlZawaalBegin.Hour
        End If
        If hlZawaalBegin.Minute < 10 Then
            sbTimeMin = "0" & hlZawaalBegin.Minute
        Else
            sbTimeMin = hlZawaalBegin.Minute
        End If
        sbTime = sbTimeHour & sbTimeMin

        'Get Salaah End Time
        If hlZawaalEnd.Hour < 10 Then
            seTimeHour = "0" & hlZawaalEnd.Hour
        Else
            seTimeHour = hlZawaalEnd.Hour
        End If
        If hlZawaalEnd.Minute < 10 Then
            seTimeMin = "0" & hlZawaalEnd.Minute
        Else
            seTimeMin = hlZawaalEnd.Minute
        End If
        seTime = seTimeHour & seTimeMin

        'Check to see if its salaah/event time and highlight accordingly
        If nTime >= sbTime AndAlso nTime <= seTime Then
            frmScreenDisplay.lblZawaal.BackColor = Color.LightSalmon
            frmScreenDisplay.lblZawaalTime.BackColor = Color.LightSalmon
            fTimesWarningLabel("zawaal")
        Else
            frmScreenDisplay.lblZawaal.BackColor = Color.Transparent
            frmScreenDisplay.lblZawaalTime.BackColor = Color.Transparent
            fTimesWarningLabel("off")
        End If
zuhr:
        'Get Current Time and Format Correctly
        If Now.Hour < 10 Then
            nTimeHour = "0" & Now.Hour
        Else
            nTimeHour = Now.Hour
        End If
        If Now.Minute < 10 Then
            nTimeMin = "0" & Now.Minute
        Else
            nTimeMin = Now.Minute
        End If
        nTime = nTimeHour & nTimeMin

        'Get Salaah Begin Time
        If hlZuhrBegin.Hour < 10 Then
            sbTimeHour = "0" & hlZuhrBegin.Hour
        Else
            sbTimeHour = hlZuhrBegin.Hour
        End If
        If hlZuhrBegin.Minute < 10 Then
            sbTimeMin = "0" & hlZuhrBegin.Minute
        Else
            sbTimeMin = hlZuhrBegin.Minute
        End If
        sbTime = sbTimeHour & sbTimeMin

        'Get Salaah End Time
        If hlZuhrEnd.Hour < 10 Then
            seTimeHour = "0" & hlZuhrEnd.Hour
        Else
            seTimeHour = hlZuhrEnd.Hour
        End If
        If hlZuhrEnd.Minute < 10 Then
            seTimeMin = "0" & hlZuhrEnd.Minute
        Else
            seTimeMin = hlZuhrEnd.Minute
        End If
        seTime = seTimeHour & seTimeMin

        'Check to see if its salaah/event time and highlight accordingly
        If nTime >= sbTime AndAlso nTime <= seTime Then
            frmScreenDisplay.lblZohr.BackColor = Color.LightGreen
            frmScreenDisplay.lblZohrTime.BackColor = Color.LightGreen
        Else
            frmScreenDisplay.lblZohr.BackColor = Color.Transparent
            frmScreenDisplay.lblZohrTime.BackColor = Color.Transparent
        End If
asr:
        If TimeAmOrPm = "PM" Then
            'Get Current Time and Format Correctly
            If Now.Hour < 10 Then
                nTimeHour = "0" & Now.Hour
            Else
                nTimeHour = Now.Hour
            End If
            If Now.Minute < 10 Then
                nTimeMin = "0" & Now.Minute
            Else
                nTimeMin = Now.Minute
            End If
            nTime = nTimeHour & nTimeMin

            'Get Salaah Begin Time
            If hlAsrBegin.Hour < 10 Then
                sbTimeHour = "0" & hlAsrBegin.Hour
            Else
                sbTimeHour = hlAsrBegin.Hour
            End If
            If hlAsrBegin.Minute < 10 Then
                sbTimeMin = "0" & hlAsrBegin.Minute
            Else
                sbTimeMin = hlAsrBegin.Minute
            End If
            sbTime = sbTimeHour & sbTimeMin

            'Get Salaah End Time
            If hlAsrEnd.Hour < 10 Then
                seTimeHour = "0" & hlAsrEnd.Hour
            Else
                seTimeHour = hlAsrEnd.Hour
            End If
            If hlAsrEnd.Minute < 10 Then
                seTimeMin = "0" & hlAsrEnd.Minute
            Else
                seTimeMin = hlAsrEnd.Minute
            End If
            seTime = seTimeHour & seTimeMin

            'Check to see if its salaah/event time and highlight accordingly
            If nTime >= sbTime AndAlso nTime <= seTime Then
                frmScreenDisplay.lblAsr.BackColor = Color.LightGreen
                frmScreenDisplay.lblAsrTime.BackColor = Color.LightGreen
            Else
                frmScreenDisplay.lblAsr.BackColor = Color.Transparent
                frmScreenDisplay.lblAsrTime.BackColor = Color.Transparent
            End If
        End If
sunset:
        If TimeAmOrPm = "PM" Then
            'Get Current Time and Format Correctly
            If Now.Hour < 10 Then
                nTimeHour = "0" & Now.Hour
            Else
                nTimeHour = Now.Hour
            End If
            If Now.Minute < 10 Then
                nTimeMin = "0" & Now.Minute
            Else
                nTimeMin = Now.Minute
            End If
            nTime = nTimeHour & nTimeMin

            'Get Salaah Begin Time
            If hlSunsetBegin.Hour < 10 Then
                sbTimeHour = "0" & hlSunsetBegin.Hour
            Else
                sbTimeHour = hlSunsetBegin.Hour
            End If
            If hlSunsetBegin.Minute < 10 Then
                sbTimeMin = "0" & hlSunsetBegin.Minute
            Else
                sbTimeMin = hlSunsetBegin.Minute
            End If
            sbTime = sbTimeHour & sbTimeMin

            'Get Salaah End Time
            If hlSunsetEnd.Hour < 10 Then
                seTimeHour = "0" & hlSunsetEnd.Hour
            Else
                seTimeHour = hlSunsetEnd.Hour
            End If
            If hlSunsetEnd.Minute < 10 Then
                seTimeMin = "0" & hlSunsetEnd.Minute
            Else
                seTimeMin = hlSunsetEnd.Minute
            End If
            seTime = seTimeHour & seTimeMin

            'Check to see if its salaah/event time and highlight accordingly
            If nTime >= sbTime AndAlso nTime <= seTime Then
                frmScreenDisplay.lblSunset.BackColor = Color.LightSalmon
                frmScreenDisplay.lblSunsetTime.BackColor = Color.LightSalmon
                fTimesWarningLabel("sunset")
            Else
                frmScreenDisplay.lblSunset.BackColor = Color.Transparent
                frmScreenDisplay.lblSunsetTime.BackColor = Color.Transparent
                fTimesWarningLabel("off")
            End If
        End If
maghrib:
        If TimeAmOrPm = "PM" Then
            'Get Current Time and Format Correctly
            If Now.Hour < 10 Then
                nTimeHour = "0" & Now.Hour
            Else
                nTimeHour = Now.Hour
            End If
            If Now.Minute < 10 Then
                nTimeMin = "0" & Now.Minute
            Else
                nTimeMin = Now.Minute
            End If
            nTime = nTimeHour & nTimeMin

            'Get Salaah Begin Time
            If hlMaghribBegin.Hour < 10 Then
                sbTimeHour = "0" & hlMaghribBegin.Hour
            Else
                sbTimeHour = hlMaghribBegin.Hour
            End If
            If hlMaghribBegin.Minute < 10 Then
                sbTimeMin = "0" & hlMaghribBegin.Minute
            Else
                sbTimeMin = hlMaghribBegin.Minute
            End If
            sbTime = sbTimeHour & sbTimeMin

            'Get Salaah End Time
            If hlMaghribEnd.Hour < 10 Then
                seTimeHour = "0" & hlMaghribEnd.Hour
            Else
                seTimeHour = hlMaghribEnd.Hour
            End If
            If hlMaghribEnd.Minute < 10 Then
                seTimeMin = "0" & hlMaghribEnd.Minute
            Else
                seTimeMin = hlMaghribEnd.Minute
            End If
            seTime = seTimeHour & seTimeMin

            'Check to see if its salaah/event time and highlight accordingly
            If nTime >= sbTime AndAlso nTime <= seTime Then
                frmScreenDisplay.lblMaghrib.BackColor = Color.LightGreen
                frmScreenDisplay.lblMaghribTime.BackColor = Color.LightGreen
            Else
                frmScreenDisplay.lblMaghrib.BackColor = Color.Transparent
                frmScreenDisplay.lblMaghribTime.BackColor = Color.Transparent
            End If
        End If
esha:
        If TimeAmOrPm = "PM" Then
            'Get Current Time and Format Correctly
            If Now.Hour < 10 Then
                nTimeHour = "0" & Now.Hour
            Else
                nTimeHour = Now.Hour
            End If
            If Now.Minute < 10 Then
                nTimeMin = "0" & Now.Minute
            Else
                nTimeMin = Now.Minute
            End If
            nTime = nTimeHour & nTimeMin

            'Get Salaah Begin Time
            If hlEshaBegin.Hour < 10 Then
                sbTimeHour = "0" & hlEshaBegin.Hour
            Else
                sbTimeHour = hlEshaBegin.Hour
            End If
            If hlEshaBegin.Minute < 10 Then
                sbTimeMin = "0" & hlEshaBegin.Minute
            Else
                sbTimeMin = hlEshaBegin.Minute
            End If
            sbTime = sbTimeHour & sbTimeMin

            'Get Salaah End Time
            If hlEshaEnd.Hour < 10 Then
                seTimeHour = "0" & hlEshaEnd.Hour
            Else
                seTimeHour = hlEshaEnd.Hour
            End If
            If hlEshaEnd.Minute < 10 Then
                seTimeMin = "0" & hlEshaEnd.Minute
            Else
                seTimeMin = hlEshaEnd.Minute
            End If
            seTime = seTimeHour & seTimeMin

            'Check to see if its salaah/event time and highlight accordingly
            If nTime >= sbTime AndAlso nTime <= 2359 Then 'We dont run full esha time as screen goes to sleep mode after 00:00am for 4 hours
                frmScreenDisplay.lblEsha.BackColor = Color.LightGreen
                frmScreenDisplay.lblEshaTime.BackColor = Color.LightGreen
            Else
                frmScreenDisplay.lblEsha.BackColor = Color.Transparent
                frmScreenDisplay.lblEshaTime.BackColor = Color.Transparent
            End If
        End If
        Exit Sub
ertrp:
        ErrorTrap()
    End Sub
    'Sub for forbidden times warning label in notice board section
    Public Sub fTimesWarningLabel(ByVal fWarningType As String)
        On Error GoTo ertrp
        'using if - check which label needs to be displayed and action request
        If fWarningType <> "" Then
            If fWarningType = "sunrise" Then
                frmScreenDisplay.tmrWarninglbl.Enabled = True
                frmScreenDisplay.lblForbiddenTimeWarning.Visible = True
                frmScreenDisplay.lblForbiddenTimeWarning.Text = "*WARNING*" & vbCrLf & "SUNRISE"
            End If
            If fWarningType = "zawaal" Then
                frmScreenDisplay.tmrWarninglbl.Enabled = True
                frmScreenDisplay.lblForbiddenTimeWarning.Visible = True
                frmScreenDisplay.lblForbiddenTimeWarning.Text = "*WARNING*" & vbCrLf & "ZAWAAL"
            End If
            If fWarningType = "sunset" Then
                frmScreenDisplay.tmrWarninglbl.Enabled = True
                frmScreenDisplay.lblForbiddenTimeWarning.Visible = True
                frmScreenDisplay.lblForbiddenTimeWarning.Text = "*WARNING*" & vbCrLf & "SUNSET"
            End If
            If fWarningType = "off" Then
                frmScreenDisplay.tmrWarninglbl.Enabled = False
                frmScreenDisplay.lblForbiddenTimeWarning.Visible = False
            End If
        Else
            frmScreenDisplay.tmrWarninglbl.Enabled = False
            frmScreenDisplay.lblForbiddenTimeWarning.Visible = False
        End If
        Exit Sub
ertrp:
        ErrorTrap()
    End Sub
End Module
